<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>弓友之家</title>
    <link rel="stylesheet" href="css/mui.css" />
    <link rel="stylesheet" href="fonts/iconfont.css" />
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
	<div class="mui-content">
		<div class="mui-scroll-wrapper" id="exchange">
		    <div class="mui-scroll">
		        <div class="exchange">
		        	<ul class="mui-table-view">
						
					</ul>
		        </div>
		    </div>
		</div>
	</div>
	<br />
	<script type="text/javascript" src="js/mui.min.js" ></script>
	<script type="text/javascript" src="js/jquery-1.8.3.min.js" ></script>
	<script type="text/javascript" src="js/common.js" ></script>
	<script type="text/javascript" charset="utf-8">
      	mui.init();
      	var page=1;
      	mui.init({ 
		    pullRefresh : {
		        container:"#exchange",
		        down : {
		            height:50,
		            auto: true,
		            contentdown : "下拉可以刷新",
		            contentover : "释放立即刷新",
		            contentrefresh : "正在刷新...",
		            callback : getList 
		        },
		        up : { 
		            height:50,
		            auto:false,
		            contentrefresh : "正在加载...",
		            contentnomore:'没有更多数据了',
		            callback : getListByPage 
		        }
		    },
		}); 
		
		function getList(){
			mui.ajax(H_SRC+'/amier/user/order_list',{
				data:{
					token:token,
					page:1,
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；            
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						var html="";
						for(var i=0;i<dataurl.length;i++){
							html+='<li class="mui-table-view-cell mui-media"><a data-id="'+dataurl[i].id+'">';
							html+='<img class="mui-media-object mui-pull-left" src="'+H_SRC+''+dataurl[i].img+'"/>';
							html+='<div class="mui-media-body">';
							html+='<h4 class="mui-ellipsis">'+dataurl[i].goodsName+'</h4>';
							html+='<p>'+dataurl[i].c_time+'</p>';
							html+='<p class="mui-ellipsis">'+dataurl[i].desc+'</p>';
							html+='<h5 class="mui-clearfix"><span>兑换成功</span><big>￥'+dataurl[i].integral+'<small>积分</small></big></h5>';
							html+='</div></a></li>';
						} 
						$('.exchange ul').html(html);
						mui('#exchange').pullRefresh().endPulldownToRefresh();
			            //重置上拉
			            mui('#exchange').pullRefresh().refresh(true);
			            page = 2;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
		function getListByPage(){
		    var _this = this;
		    mui.ajax(H_SRC+'/amier/user/order_list',{
				data:{
					page:page,
					token:token
				},
				dataType:'json',//服务器返回json格式数据
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；
				headers:{'Authorization':token},              
				success:function(data){
					var dataurl=data.data;
					if(data.code == 401)
					{
						mui.openWindow({
							url:'login.html',
							id:'login.html'
						})
					}else if(data.code == 1) 
					{
						var dataurl=data.data;
						if(dataurl.length == 0){
			                _this.endPullupToRefresh(true);
			                return false;
			            }
						
						for(var i=0;i<dataurl.length;i++){ 
							var html="";
							html+='<li class="mui-table-view-cell mui-media"><a data-id="'+dataurl[i].id+'">';
							html+='<img class="mui-media-object mui-pull-left" src="'+H_SRC+''+dataurl[i].img+'"/>';
							html+='<div class="mui-media-body">';
							html+='<h4 class="mui-ellipsis">'+dataurl[i].goodsName+'</h4>';
							html+='<p>'+dataurl[i].c_time+'</p>';
							html+='<p class="mui-ellipsis">'+dataurl[i].desc+'</p>';
							html+='<h5 class="mui-clearfix"><span>兑换成功</span><big>￥'+dataurl[i].integral+'<small>积分</small></big></h5>';
							html+='</div></a></li>';
							$('.exchange ul').append(html);
						}
						_this.endPullupToRefresh(false);
		            	page++;
					}else{ 
						mui.toast(data.msg);
					}
				},
				error:function(){
				}
			}) 
		}
    </script>
</body>
</html>